package admin

import (
	"github.com/gin-gonic/gin"
	"net/http"
	"shangyuapi/data_source"
	"shangyuapi/models"
)

func Fuwus(ctx *gin.Context) {

	var users []models.Fuwu

	data_source.Db.Find(&users)

	ctx.JSON(http.StatusOK, gin.H{
		"code":    0,
		"error":   0,
		"success": 200,
		"data":    users,
		"msg":     "ok",
	})
	return

}

type FuwupriceBody struct {
	ID    int64   `json:"id" gorm:"id"`
	Name  string  `json:"name" gorm:"name"`
	Price float64 `json:"price" gorm:"price"`
}

func Fuwupriceupdate(ctx *gin.Context) {
	request := FuwupriceBody{}
	ctx.ShouldBind(&request)
	id := request.ID
	price := request.Price
	data_source.Db.Model(&models.Fuwu{}).Where("id = ?", id).Update("price", price)
	ctx.JSON(http.StatusOK, gin.H{
		"code":    0,
		"error":   0,
		"success": 200,
		"data":    "ok",
		"msg":     "ok",
	})
	return

}
